# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>

_realname=corrosion
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.5.2
pkgrel=1
pkgdesc="Tool for integrating Rust into an existing CMake project (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/corrosion-rs/corrosion'
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-rust" "${MINGW_PACKAGE_PREFIX}-cmake")
makedepends=("${MINGW_PACKAGE_PREFIX}-ninja")
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('6bc02411e29183a896aa60c58db6819ec6cf57c08997481d0b0da9029356b529')

build() {
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      -DCMAKE_INSTALL_LIBEXECDIR=lib \
      -S "${_realname}-${pkgver}" \
      -B "build-${MSYSTEM}"

  cmake --build "build-${MSYSTEM}"
}

check() {
  ctest --test-dir "build-${MSYSTEM}" || warning "Tests failed"
}

package() {
  DESTDIR="${pkgdir}" cmake --install "build-${MSYSTEM}"

  install -Dm644 "${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
